{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Cookie 在计算机中是个存储在浏览器目录中的文本文件，当浏览器运行时，存储在 RAM 中发挥作用 （此种 Cookies 称作 Session Cookies），一旦用户从该网站或服务器退出，Cookie 可存储在用户本地的硬盘上 （此种 Cookies 称作 Persistent Cookies） 。\n",
    "\n",
    "通常情况下，当用户结束浏览器会话时，系统将终止所有的 Cookie。当 Web 服务器创建了Cookies 后，只要在其有效期内，当用户访问同一个 Web 服务器时，浏览器首先要检查本地的Cookies，并将其原样发送给 Web 服务器。这种状态信息称作“Persistent Client State HTTP Cookie” ，简称为 Cookies。\n",
    "\n",
    "Cookie 是在 HTTP 协议下，服务器或脚本可以维护客户工作站上信息的一种方式。Cookie 是由 Web 服务器保存在用户浏览器（客户端）上的小文本文件，它可以包含有关用户的信息。无论何时用户链接到服务器，Web 站点都可以访问 Cookie 信息 。\n",
    "目前有些 Cookie 是临时的，有些则是持续的。临时的 Cookie 只在浏览器上保存一段规定的时间，一旦超过规定的时间，该 Cookie 就会被系统清除。\n",
    "持续的 Cookie 则保存在用户的 Cookie 文件中，下一次用户返回时，仍然可以对它进行调用。在 Cookie 文件中保存 Cookie，有些用户担心 Cookie 中的用户信息被一些别有用心的人窃取，而造成一定的损害。其实，网站以外的用户无法跨过网站来获得 Cookie 信息。如果因为这种担心而屏蔽 Cookie，肯定会因此拒绝访问许多站点页面。因为，当今有许多 Web 站点开发人员使用 Cookie 技术，例如 Session 对象的使用就离不开 Cookie 的支持。                                                                                                                                                                                               ----来自百度百科"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "cookies={\"csrftoken\":\"****\",\"messages\":'****',\"sessionid\":\"****\"}#填上你自己的cookies信息\n",
    "r=requests.get(\"http://www.fxdayu.com\",cookies=cookies)\n",
    "r=requests.get(\"http://www.fxdayu.com/navbar/top/account?t=1533078863\",cookies=cookies)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# r.text\n",
    "r=requests.get(\"http://www.fxdayu.com/tutorials/docs/17/\",cookies=cookies)\n",
    "dataS=r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://www.fxdayu.com/tutorials/doc_content/237\n",
      "237\n",
      "https://www.zybuluo.com/Channelchan/note/1065836\n",
      "Fxdayu数据分析与研究环境安装\n",
      "http://www.fxdayu.com/tutorials/doc_content/186\n",
      "186\n",
      "https://www.zybuluo.com/Channelchan/note/1066051\n",
      "环境安装_Windows64位\n",
      "http://www.fxdayu.com/tutorials/doc_content/182\n",
      "182\n",
      "https://www.zybuluo.com/Channelchan/note/1066199\n",
      "环境安装_OSX\n",
      "http://www.fxdayu.com/tutorials/doc_content/75\n",
      "75\n",
      "https://www.zybuluo.com/Channelchan/note/644580\n",
      "Python 基础语法\n",
      "http://www.fxdayu.com/tutorials/doc_content/76\n",
      "76\n",
      "https://www.zybuluo.com/Channelchan/note/644599\n",
      "Python 数据类型\n",
      "http://www.fxdayu.com/tutorials/doc_content/78\n",
      "78\n",
      "https://www.zybuluo.com/Channelchan/note/644606\n",
      "Python 数据运算\n",
      "http://www.fxdayu.com/tutorials/doc_content/66\n",
      "66\n",
      "https://www.zybuluo.com/Channelchan/note/644637\n",
      "Python 流程控制\n",
      "http://www.fxdayu.com/tutorials/doc_content/79\n",
      "79\n",
      "https://www.zybuluo.com/Channelchan/note/644646\n",
      "Python 函数设计\n",
      "http://www.fxdayu.com/tutorials/doc_content/73\n",
      "73\n",
      "https://www.zybuluo.com/Channelchan/note/644665\n",
      "Python模块导入\n",
      "http://www.fxdayu.com/tutorials/doc_content/238\n",
      "238\n",
      "https://www.zybuluo.com/Channelchan/note/1080782\n",
      "Python内建函数\n",
      "http://www.fxdayu.com/tutorials/doc_content/236\n",
      "236\n",
      "https://www.zybuluo.com/Channelchan/note/1081375\n",
      "Python递归函数\n",
      "http://www.fxdayu.com/tutorials/doc_content/239\n",
      "239\n",
      "https://www.zybuluo.com/Channelchan/note/1081382\n",
      "Python高级特性\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "base_url=\"http://www.fxdayu.com/tutorials/doc_content/\"\n",
    "if not os.path.exists(\"channel\"):\n",
    "    os.mkdir(\"channel\")\n",
    "os.chdir(\"channel\")\n",
    "for d in dataS:\n",
    "    id_=str(d[\"id\"])\n",
    "    title=d[\"title\"]\n",
    "    url=base_url+id_\n",
    "    print(url)\n",
    "    r=requests.get(url,cookies=cookies)\n",
    "    print(id_)\n",
    "    print(r.json()[\"zy_url\"])\n",
    "    print(title)\n",
    "    article_url=(r.json())[\"zy_url\"]\n",
    "    r=requests.get(article_url)\n",
    "    with open(title+\".html\",\"w\",encoding=\"utf-8\") as f:\n",
    "        f.write(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
